<template>
  <div class="classify">
    <van-nav-bar title="分类" fixed placeholder/>
    <van-search
        v-model="value"
        placeholder="新春大促销"
        shape="round"
    />

    <div class="shop">
      <van-sidebar v-model="activeKey">
      <van-sidebar-item title="推荐分类" />
      <van-sidebar-item title="全球奶粉" />
      <van-sidebar-item title="尿不湿" />
      </van-sidebar>

      <div class="shop-detail">
        <div v-for="value in list" :key="value.title" @click="goDetail(value.productId)">
          <img :src="value.imgUrl" alt="">
          <p>{{value.title}}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getClassifyApi } from "@/utils/api.js";
export default {
  data() {
    return {
      value: "",
      activeKey: 0,
      list: [],
      type: "1"
    };
  },

  components: {},

  computed: {},
  created() {
    this.getDate();
  },
  watch: {
    activeKey() {
      this.getDate();
    }
  },

  methods: {
    async getDate() {
      const res = await getClassifyApi({ type: this.activeKey + 1 });
      if (res.status === "0") {
        this.list = res.result;
      }
    },
    goDetail(id) {
      console.log(id);
      this.$router.push("/detail/" + id);
    }
  }
};
</script>

<style lang="less" scoped>
.classify {
  .shop {
    display: flex;
    .van-sidebar {
      flex: 1;
    }
    .shop-detail {
      flex: 2;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      font-size: 12px;
      background-color: #fff;
      div {
        width: 100px;
        height: 100px;
        display: flex;
        flex-direction: column;
        align-items: center;

        margin: 0 10px 10px;
      }
      img {
        width: 60px;
        height: 60px;
      }
    }
  }
}
</style>
